package com.example.demoapp.activity;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;

import com.example.demoapp.R;
import com.example.demoapp.bean.User;
import com.google.gson.Gson;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PersonInfoActivity extends AppCompatActivity {
    @BindView(R.id.nickname)
    TextView nickname;
    @BindView(R.id.username)
    TextView username;
        @BindView(R.id.email)
    TextView email;
    @BindView(R.id.phonenumber)
    TextView phonenumber;
    @BindView(R.id.sex)
    TextView sex;
    @BindView(R.id.birthday)
    TextView birthday;

    private Context mContext;
    SharedPreferences sharedPreferences;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person_info);
        ButterKnife.bind(this);// bindview
        mContext = this;
        sharedPreferences = mContext.getSharedPreferences("LoginPrefs", Context.MODE_PRIVATE);
        User user = new Gson().fromJson(sharedPreferences.getString("user",""),User.class);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ActionBar bar = getSupportActionBar();
        if (bar != null) {
            bar.setTitle("个人信息");
            bar.setDisplayHomeAsUpEnabled(true);
            bar.setHomeButtonEnabled(true);
        }

        nickname.setText(user.getNickName());
        phonenumber.setText(user.getPhonenumber());
        email.setText(user.getEmail());
        sex.setText(user.getSex());
        birthday.setText(user.getCreateTime());
        username.setText(user.getUserName());
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}